<template>
    <div>
        <!--  搜索框 -->
        <div class="search">
            <div class="content">
                <div class="title">你好，世界！</div>
                <div class="input">
                    <el-input v-model="input" @blur="close" @fouce="open" placeholder="搜索国家、城市、目的地"></el-input>
                    <el-button class="button">搜索</el-button>
                </div>

                <!-- 搜索下拉框 -->
                <div class="list" v-show="isShow">
                    <ul v-if="list.length > 0">
                        <li v-for="item in list" :key="item.id">{{ item.name }}</li>
                    </ul>
                    <div v-if="list.length <= 0 && mark" class="loading">数据加载中...</div>
                </div>
            </div>
        </div>
        <!-- 实时热门Top10 -->
        <div class="wrapper">
        </div>
    </div>
</template>

<script>
export default {
    name: 'IndexView',
    data() {
        return {
            input: '',
            isShow: false,
            list: [],
            mark: true,
        }
    },
    watch: {
        input(val) {
            if (!val) {
                this.isShow = false;
                return;
            }
            this.isShow = true;

            this.getDestSearch(val)
        }
    },
    methods: {
        //网络请求
        async getDestSearch(val) {
            let res = await this.$api.getDestSearch({
                keyword: val
            })
            console.log("搜索目的接口", res);

            //判断无数据的情况
            this.list = res.data.list

            //状态标识 无数据
            if (this.list.length == 0) {
                this.mark = true
            }
        },

        close() {
            this.isShow = false
        },
        open() {
            if (!this.input) {
                this.isShow = true;
            } else {
                this.isShow = false;
            }
        }
    }
}
</script>

<style scoped>
.search {
    background: #efefef url('@/assets/images/8.png') no-repeat top;
    height: 500px;
    background-size: cover;
    display: flex;
    align-items: center;

    .content {
        margin: 0 auto;
        width: 760px;
        text-align: center;
        position: relative;

        .list {
            position: absolute;
            width: 621px;
            min-height: 100px;
            background: #fff;
            top: 135px;
            border-radius: 6px;
            text-align: left;
            overflow: hidden;

            li {
                line-height: 30px;
                font-size: 15px;
                border-bottom: 1px solid #eee;
                padding-left: 20px;
                padding-right: 20px;
            }

            li:hover {
                background: rgb(190, 229, 132);
            }

            .loading {
                color: #999;
                line-height: 100px;
                text-align: center;
            }
        }

        .title {
            font-size: 56px;
            color: #fff;
            font-weight: 700;
            text-shadow: 0 5px 5px rgba(0, 0, 0, .1);
            margin-bottom: 20px;
        }

        .input {
            display: flex;

            .button {
                width: 160px;
                background: rgb(151, 217, 242);
            }

            .button:hover {
                color: rgb(255, 255, 255);
            }
        }
    }
}


::v-deep .el-input__inner {
    height: 50px;
}

.wrapper {
    height: 400px;
}
</style>